package com.easepal7506a.project.ui.presenter;


import android.text.TextUtils;

import com.easepal.socketiolib.model.SocketModel;
import com.easepal7506a.project.Constant.CommmandNum;
import com.ogawa.base.Constant.Constants;
import com.easepal7506a.project.manager.DataManager;
import com.easepal7506a.project.observer.SocketDataObserver;
import com.easepal7506a.project.ui.iview.IFraMassageView7506;

import io.reactivex.disposables.Disposable;

/**
 * Created by FHB on 2018/4/1.
 */

public class FraMassagePresenter7506 implements SocketDataObserver.SocketReceive {
    IFraMassageView7506 mView;
    private int mDingdian;//1定点  0非
    private int mQujian;//1区间  0非

    private int mAreaPosition;
    private boolean isPositionChange = false;//定点区间是否改变
    private Disposable mDisposable;

    private boolean hasDingdianChange;
    private boolean hasQujianChange;
    private boolean flag;
    public FraMassagePresenter7506(IFraMassageView7506 view) {
        mView = view;
        SocketDataObserver.getInst().registerObserver(this);
    }
    public void setknead(String value){
        if(!TextUtils.isEmpty(value)){
            if(value.equals("2")){
                //揉捏2挡
                mView.getSkill(0,2);
            }else if(value.equals("1")){
                //揉捏1挡
                mView.getSkill(0,1);
            }
            else {
                mView.getSkill(0,0);
            }
        }

    }

    // //在运行的手动程序（除揉捏）推拿10 瑞典1	21瑞典2	22敲击1	31敲击2	32指压1	41指压2	42揉敲1	51揉敲2	52拍打1	61拍打2	62
    public void setHand(String value){
        if(!TextUtils.isEmpty(value)){
            if(value.equals(Constants.HAND_VALUE_TUIN)){
                //推拿
                mView.getSkill(2,1);
            }
            else {
                mView.getSkill(2,0);
            }

            if(value.equals(Constants.HAND_VALUE_PD2)){
                //拍打2挡
                mView.getSkill(4,2);
            }else if(value.equals(Constants.HAND_VALUE_PD1)){
                //拍打1挡
                mView.getSkill(4,1);
            } else {
                mView.getSkill(4,0);
            }

            if(value.equals(Constants.HAND_VALUE_QJ2)){
                //敲击2挡
                mView.getSkill(1,2);
            }else if(value.equals(Constants.HAND_VALUE_QJ1)){
                //敲击1挡
                mView.getSkill(1,1);
            } else {
                mView.getSkill(1,0);
            }

            if(value.equals(Constants.HAND_VALUE_ZY2)){
                //指压2挡
                mView.getSkill(3,2);
            }else if(value.equals(Constants.HAND_VALUE_ZY1)){
                //指压1挡
                mView.getSkill(3,1);
            } else {
                mView.getSkill(3,0);
            }
            if(value.equals(Constants.HAND_VALUE_RD2)){
                //瑞典2挡
                mView.getSkill(5,2);
            }else if(value.equals(Constants.HAND_VALUE_RD1)){
                //瑞典1挡
                mView.getSkill(5,1);
            } else {
                mView.getSkill(5,0);
            }
        }

    }
    public void setWidth(String value){
        if(!TextUtils.isEmpty(value)){
            mView.getWidth(Integer.valueOf(value));
        }

    }
    public void setPower(String value){
        if(!TextUtils.isEmpty(value)){
            mView.getPower(Integer.valueOf(value));
        }

    }
    public void set3D(String value){
        if(!TextUtils.isEmpty(value)){
            mView.get3D(Integer.valueOf(value));
        }

    }
    public void setSpeed(String value){
        if(!TextUtils.isEmpty(value)){
            mView.getSpeed(Integer.valueOf(value));
        }

    }
    public void setPoint(String value){
        if(!TextUtils.isEmpty(value)){
            mView.getPoint(Integer.valueOf(value));
        }

    }
    public void setDinddian(){
        int area = 0;
        if(!TextUtils.isEmpty(DataManager.getInst().getValue(CommmandNum.mStatusDingdian))&&DataManager.getInst().getValue(CommmandNum.mStatusDingdian).equals("1")){
            area=1;//定点

        }
        else if(!TextUtils.isEmpty(DataManager.getInst().getValue(CommmandNum.mStatusQujian))&&DataManager.getInst().getValue(CommmandNum.mStatusQujian).equals("1")){
            //区间
            area=2;
        }
        else {
            area =0;
        }
        mView.getArea(area);
    }
    @Override
    public void onRceiveSocket(SocketModel model) {
        String key = model.getKey();
        String value = model.getValue();
        //揉捏 单独一档
        if(model.getKey().equals(CommmandNum.mStatusKnead)){
            setknead(value);
        }
        //手法
        else if(model.getKey().equals(CommmandNum.mStatusHand)){
            setHand(value);
        }
        //宽度
        else if(model.getKey().equals(CommmandNum.mStatusWidth)){
            setWidth(value);
        }
        //力度
        else if(model.getKey().equals(CommmandNum.mStatusStrength)){
            setPower(value);

        }
        //速度
        else if(model.getKey().equals(CommmandNum.mStatusSpeed)){
            setSpeed(value);

        }

        //3d
        else if(model.getKey().equals(CommmandNum.mStatus3D)){
            set3D(value);

        }
        //定点
        else if(model.getKey().equals(CommmandNum.mStatusDingdian)){
            mDingdian = Integer.valueOf(value);
            if(mDingdian==1){
                mAreaPosition=1;//定点
            }
            else if(mQujian==1){
                //区间
                mAreaPosition=2;
            }
            else {
                mAreaPosition =0;
            }
            mView.getArea(mAreaPosition);

        }
        //区间
        else if(model.getKey().equals(CommmandNum.mStatusQujian)){
            mQujian = Integer.valueOf(value);
            if(mDingdian==1){
                mAreaPosition=1;//定点
            }
            else if(mQujian==1){
                //区间
                mAreaPosition=2;
            }
            else {
                mAreaPosition =0;
            }
            mView.getArea(mAreaPosition);

        }

        else  if(key.equals(CommmandNum.mStatusPointPosition)){
            setPoint(value);

        }


    }


    public void onDestory(){
        SocketDataObserver.getInst().removeObserver(this);
    }
}
